import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_changdian_football/global.dart';
import 'package:flutter_changdian_football/pages/mine/user_store.dart';
import 'package:flutter_changdian_football/widget/dialog/pact_dialog.dart';
import 'package:get/get.dart';

class MainController extends GetxController {
  static MainController get to => Get.find();

  late final PageController pageController;

  int currentPage = 0;

  int lastTime = 0;

  @override
  void onInit() {
    super.onInit();
    pageController = PageController(initialPage: currentPage);

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      bool isPact = SpUtil.getBool('isPact') ?? false;
      if (isPact == false) {
        PactDialog.show(
          Get.context!,
          confirmTap: () {
            Global.setLocationApiKey();
            SpUtil.putBool('isPact', true);
            Get.back();
            UserStore.to.checkVersion(false);
          },
          abolishTap: () {
            SystemNavigator.pop();
          }
        );
      } else {
        UserStore.to.checkVersion(false);
      }
    });
  }


  void jumpToPage(int page) {
    pageController.jumpToPage(page);
  }

  void changePage(int page) {
    currentPage = page;
    update();
  }

  @override
  void onClose() {
    pageController.dispose();
    super.onClose();
  }

}